-- DarkDragon
-- Created by zouyb Dec/29/2015
-- 黑暗龙雕像

require "game/ui/form/dungeon/special/UIDarkDragonStatue"

-- 初始化
function initDarkDragon(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 打开黑暗龙雕像界面
            local uiForm = UIDarkDragonStatue.create(self.gridData);
            UIMgr.getCurrentScene():removeFormByName("UIDarkDragonStatue");
            UIMgr.getCurrentScene():addForm(uiForm);
            -- 音效
            AudioM.playFx("workshop_store");
        end
    end

    -- 建筑图标
    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;
end
